package com.bdqn.desiremall.command;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.bdqn.desiremall.entity.Mall_Order;
import com.bdqn.desiremall.serivce.order.OrderSerivce;
import com.bdqn.desiremall.serivce.order.OrderSerivceImpl;
import com.mvc.command.ICommand;

public class OrderCommand  implements ICommand{
	OrderSerivce orderSerivce=new OrderSerivceImpl();
	List<Mall_Order> ordersList=null;
	Mall_Order order=null;
	/**
	 * 根据用户id查询订单
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void getAllOrder(HttpServletRequest request, HttpServletResponse response)
			throws Exception{
		String orderId=request.getParameter("orderId");
		order=new Mall_Order();
		if(null != orderId){
			order.setOrderId(Integer.valueOf(orderId));
		}
		ordersList=orderSerivce.orderView(order);
		if(null !=ordersList ){
			request.setAttribute("ordersList", ordersList);
			request.getRequestDispatcher("").forward(request, response);
		}else{
			response.sendRedirect("");
		}
		
	}
	/**
	 * 取消订单
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void ModifyOrder(HttpServletRequest request, HttpServletResponse response)
	throws Exception{
		String orderId=request.getParameter("orderId");
		boolean is=false;
		if(null != orderId){
			is=orderSerivce.cancelTheOrder(Integer.valueOf(orderId));
		}
       if(is){
    	   //取消订单成功
    	  response.sendRedirect("Order.do?method=getAllOrder");
       }else{
    	 //取消订单是失败
    	   response.sendRedirect("Order.do?method=getAllOrder");
       }
		
	}
	public void addOrder(HttpServletRequest request, HttpServletResponse response)
			throws Exception{
		String orderId=request.getParameter("orderId");
	}
	
	
	
	OrderSerivce orderService = new OrderSerivceImpl();
	//订单列表
	public void orderList(HttpServletRequest request,HttpServletResponse response){
		Mall_Order order =new Mall_Order();
		List<Mall_Order> orderView = orderService.orderView(order);
		HttpSession session = request.getSession();
		session.setAttribute("orderList", orderView);
	}
}
